package hsb.ruoyi.common.utils;

import java.util.regex.Pattern;

/**
 * @author 胡帅博
 * @date 2022/9/3 11:24
 */
public class PhoneUtils {
//    static String chinaMatch = "^(\\+?0?86\\-?)?1[345789]\\d{9}$";
//    static String canadaMatch = "^(\\+?1)?[2-9]\\d{2}[2-9](?!11)\\d{6}$";
//

    static Pattern chinaPattern = Pattern.compile("^(\\+?0?86\\-?)?1[345789]\\d{9}$");
    static Pattern canadaPattern = Pattern.compile("^(\\+?1)?[2-9]\\d{2}[2-9](?!11)\\d{6}$");

    public static void main(String[] args) {
        System.out.println(verifyPhone("2383799361"));
    }


    public static boolean verifyPhone(String phone) {
        //todo 手机号验证
        if (phone == null && phone.equals("")) {
            return false;
        }
        // 验证是不是加拿大或者中国的手机号
        return chinaPattern.matcher(phone).matches();
    }

    public static boolean verifyCanadaPhone(String phone) {
        //todo 手机号验证
        if (phone == null && phone.equals("")) {
            return false;
        }
        // 验证是不是加拿大手机号
        return canadaPattern.matcher(phone).matches();
    }


}
